home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / 3dview12.zip / VESAPROC.CPP < prev    next >
Text File  |  1996-05-28  |  14KB  |  399 lines

  1. void VESA_Pix8BC ( long X , long Y , unsigned long C , unsigned short Selector ) {
  2.     if ( X < VESA_MinX ) return;
  3.     if ( X > VESA_MaxX ) return;
  4.     if ( Y < VESA_MinY ) return;
  5.     if ( Y > VESA_MaxY ) return;
  6.     *(char far*)( Selector :> (char*)( Y * VESA_BpL + X ) ) = char( C );
  7. };
  8.  
  9. void VESA_FilledTriangleTex8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  10.                                 long tx1, long ty1, long tx2, long ty2,
  11.                                 long tx3, long ty3, DWORD MUL, WORD S ) {
  12.     long m,i;
  13.     long x12,x13,x23,m12,m13,m23;
  14.     long tx12,tx13,tx23,mtx12,mtx13,mtx23;
  15.     long ty12,ty13,ty23,mty12,mty13,mty23;
  16.     if ( y1 >= y2 ) {
  17.         m = y1; y1 = y2; y2 = m;
  18.         m = x1; x1 = x2; x2 = m;
  19.         m = tx1; tx1 = tx2; tx2 = m; 
  20.         m = ty1; ty1 = ty2; ty2 = m; };
  21.     if ( y2 >= y3 ) {
  22.         m = y2; y2 = y3; y3 = m;
  23.         m = x2; x2 = x3; x3 = m;
  24.         m = tx2; tx2 = tx3; tx3 = m; 
  25.         m = ty2; ty2 = ty3; ty3 = m; };
  26.     if ( y1 >= y2 ) {
  27.         m = y1; y1 = y2; y2 = m;
  28.         m = x1; x1 = x2; x2 = m;
  29.         m = tx1; tx1 = tx2; tx2 = m; 
  30.         m = ty1; ty1 = ty2; ty2 = m; };
  31.     x12 = x1 << 16;
  32.     x13 = x1 << 16;
  33.     x23 = x2 << 16;
  34.     tx12 = tx1 << 16;
  35.     tx13 = tx1 << 16;
  36.     tx23 = tx2 << 16;
  37.     ty12 = ty1 << 16;
  38.     ty13 = ty1 << 16;
  39.     ty23 = ty2 << 16;
  40.     if ( y2 != y1 ) { m12   = ( (  x2 -  x1 ) << 16 ) / ( y2 - y1 );
  41.                       mtx12 = ( ( tx2 - tx1 ) << 16 ) / ( y2 - y1 ); 
  42.                       mty12 = ( ( ty2 - ty1 ) << 16 ) / ( y2 - y1 ); };
  43.     if ( y3 != y1 ) { m13  = ( ( x3 - x1 ) << 16 ) / ( y3 - y1 ); 
  44.                       mtx13 = ( ( tx3 - tx1 ) << 16 ) / ( y3 - y1 ); 
  45.                       mty13 = ( ( ty3 - ty1 ) << 16 ) / ( y3 - y1 ); };
  46.     if ( y3 != y2 ) { m23  = ( ( x3 - x2 ) << 16 ) / ( y3 - y2 ); 
  47.                       mtx23 = ( ( tx3 - tx2 ) << 16 ) / ( y3 - y2 ); 
  48.                       mty23 = ( ( ty3 - ty2 ) << 16 ) / ( y3 - y2 ); };
  49.     for ( i = y1; i < y2; i++ ) {
  50.         VESA_HLineTex8B( x12 >> 16, x13 >> 16, i, tx12, ty12, tx13, ty13,
  51.                          MUL, S );
  52.         x12 += m12;
  53.         x13 += m13;
  54.         tx12 += mtx12;
  55.         ty12 += mty12;
  56.         tx13 += mtx13;
  57.         ty13 += mty13; };
  58.     for ( ; i <= y3; i++ ) {
  59.         VESA_HLineTex8B( x13 >> 16, x23 >> 16, i, tx13, ty13, tx23, ty23,
  60.                          MUL, S );
  61.         x13 += m13;
  62.         x23 += m23;
  63.         tx13 += mtx13;
  64.         ty13 += mty13;
  65.         tx23 += mtx23;
  66.         ty23 += mty23; };
  67. };
  68.  
  69. void VESA_FilledTriangleTexZ8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  70.                                  long tx1, long ty1, long tx2, long ty2,
  71.                                  long tx3, long ty3, long z1, long z2, long z3,
  72.                                  DWORD MUL, WORD ZSEL, WORD S ) {
  73.     long m,i;
  74.     long x12,x13,x23,m12,m13,m23;
  75.     long tx12,tx13,tx23,mtx12,mtx13,mtx23;
  76.     long ty12,ty13,ty23,mty12,mty13,mty23;
  77.     long z12,z13,z23,mz12,mz13,mz23;
  78.     if ( y1 >= y2 ) {
  79.         m = y1; y1 = y2; y2 = m;
  80.         m = x1; x1 = x2; x2 = m;
  81.         m = z1; z1 = z2; z2 = m;
  82.         m = tx1; tx1 = tx2; tx2 = m; 
  83.         m = ty1; ty1 = ty2; ty2 = m; };
  84.     if ( y2 >= y3 ) {
  85.         m = y2; y2 = y3; y3 = m;
  86.         m = x2; x2 = x3; x3 = m;
  87.         m = z2; z2 = z3; z3 = m;
  88.         m = tx2; tx2 = tx3; tx3 = m; 
  89.         m = ty2; ty2 = ty3; ty3 = m; };
  90.     if ( y1 >= y2 ) {
  91.         m = y1; y1 = y2; y2 = m;
  92.         m = x1; x1 = x2; x2 = m;
  93.         m = z1; z1 = z2; z2 = m;
  94.         m = tx1; tx1 = tx2; tx2 = m; 
  95.         m = ty1; ty1 = ty2; ty2 = m; };
  96.     x12 = x1 << 16;
  97.     x13 = x1 << 16;
  98.     x23 = x2 << 16;
  99.     z12 = z1;
  100.     z13 = z1;
  101.     z23 = z2;
  102.     tx12 = tx1 << 16;
  103.     tx13 = tx1 << 16;
  104.     tx23 = tx2 << 16;
  105.     ty12 = ty1 << 16;
  106.     ty13 = ty1 << 16;
  107.     ty23 = ty2 << 16;
  108.     if ( y2 != y1 ) { m12   = ( ( x2 - x1 ) << 16 ) / ( y2 - y1 );
  109.                       mz12   = ( ( z2 - z1 ) ) / ( y2 - y1 );
  110.                       mtx12 = ( ( tx2 - tx1 ) << 16 ) / ( y2 - y1 ); 
  111.                       mty12 = ( ( ty2 - ty1 ) << 16 ) / ( y2 - y1 ); };
  112.     if ( y3 != y1 ) { m13  = ( ( x3 - x1 ) << 16 ) / ( y3 - y1 ); 
  113.                       mz13   = ( ( z3 - z1 ) ) / ( y3 - y1 );
  114.                       mtx13 = ( ( tx3 - tx1 ) << 16 ) / ( y3 - y1 ); 
  115.                       mty13 = ( ( ty3 - ty1 ) << 16 ) / ( y3 - y1 ); };
  116.     if ( y3 != y2 ) { m23  = ( ( x3 - x2 ) << 16 ) / ( y3 - y2 ); 
  117.                       mz23   = ( ( z3 - z2 ) ) / ( y3 - y2 );
  118.                       mtx23 = ( ( tx3 - tx2 ) << 16 ) / ( y3 - y2 ); 
  119.                       mty23 = ( ( ty3 - ty2 ) << 16 ) / ( y3 - y2 ); };
  120.     for ( i = y1; i < y2; i++ ) {
  121.         VESA_HLineTexZ8B( x12 >> 16, x13 >> 16, i, tx12, ty12, tx13, ty13, z12, z13,
  122.                          MUL, ZSEL, S );
  123.         x12 += m12;
  124.         x13 += m13;
  125.         z12 += mz12;
  126.         z13 += mz13;
  127.         tx12 += mtx12;
  128.         ty12 += mty12;
  129.         tx13 += mtx13;
  130.         ty13 += mty13; };
  131.     for ( ; i <= y3; i++ ) {
  132.         VESA_HLineTexZ8B( x13 >> 16, x23 >> 16, i, tx13, ty13, tx23, ty23, z13, z23,
  133.                          MUL, ZSEL, S );
  134.         x13 += m13;
  135.         x23 += m23;
  136.         z13 += mz13;
  137.         z23 += mz23;
  138.         tx13 += mtx13;
  139.         ty13 += mty13;
  140.         tx23 += mtx23;
  141.         ty23 += mty23; };
  142. };
  143.  
  144. void VESA_FilledTriangleZBuf8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  145.                                   long z1, long z2, long z3,
  146.                                   DWORD C, WORD ZSEL, WORD S ) {
  147.     long m,i;
  148.     long x12,x13,x23,m12,m13,m23;
  149.     long z12,z13,z23;
  150.     long mz12,mz13,mz23;
  151.     if ( y1 >= y2 ) {
  152.         m = y1; y1 = y2; y2 = m;
  153.         m = x1; x1 = x2; x2 = m;
  154.         m = z1; z1 = z2; z2 = m; };
  155.     if ( y2 >= y3 ) {
  156.         m = y2; y2 = y3; y3 = m;
  157.         m = x2; x2 = x3; x3 = m;
  158.         m = z2; z2 = z3; z3 = m; };
  159.     if ( y1 >= y2 ) {
  160.         m = y1; y1 = y2; y2 = m;
  161.         m = x1; x1 = x2; x2 = m;
  162.         m = z1; z1 = z2; z2 = m; };
  163.     x12 = x1 << 16;
  164.     x13 = x1 << 16;
  165.     x23 = x2 << 16;
  166.     z12 = z1;
  167.     z13 = z1;
  168.     z23 = z2;
  169.     if ( y2 != y1 ) { m12  = ( ( x2 - x1 ) << 16 ) / ( y2 - y1 );
  170.                       mz12 = ( z2 - z1 ) / ( y2 - y1 ); };
  171.     if ( y3 != y1 ) { m13  = ( ( x3 - x1 ) << 16 ) / ( y3 - y1 ); 
  172.                       mz13 = ( z3 - z1 ) / ( y3 - y1 ); };
  173.     if ( y3 != y2 ) { m23  = ( ( x3 - x2 ) << 16 ) / ( y3 - y2 ); 
  174.                       mz23 = ( z3 - z2 ) / ( y3 - y2 ); };
  175.     for ( i = y1; i < y2; i++ ) {
  176.         VESA_HLineZ8B( x12 >> 16, x13 >> 16, i, z12, z13, C, ZSEL, S );
  177.         x12 += m12;
  178.         x13 += m13;
  179.         z12 += mz12;
  180.         z13 += mz13; };
  181.     for ( ; i <= y3; i++ ) {
  182.         VESA_HLineZ8B( x23 >> 16, x13 >> 16, i, z23, z13, C, ZSEL, S );
  183.         x13 += m13;
  184.         x23 += m23;
  185.         z13 += mz13;
  186.         z23 += mz23; };
  187. };
  188.  
  189. void VESA_FilledTriangleGZBuf8BC( long x1, long y1, long x2, long y2, long x3, long y3,
  190.                                    long z1, long z2, long z3, long c1, long c2, long c3,
  191.                                    WORD ZSEL, WORD S ) {
  192.     long m,i;
  193.     long x12,x13,x23,m12,m13,m23;
  194.     long z12,z13,z23,mz12,mz13,mz23;
  195.     long c12,c13,c23,mc12,mc13,mc23;
  196.     if ( y1 >= y2 ) {
  197.         m = y1; y1 = y2; y2 = m;
  198.         m = x1; x1 = x2; x2 = m;
  199.         m = c1; c1 = c2; c2 = m;
  200.         m = z1; z1 = z2; z2 = m; };
  201.     if ( y2 >= y3 ) {
  202.         m = y2; y2 = y3; y3 = m;
  203.         m = x2; x2 = x3; x3 = m;
  204.         m = c2; c2 = c3; c3 = m;
  205.         m = z2; z2 = z3; z3 = m; };
  206.     if ( y1 >= y2 ) {
  207.         m = y1; y1 = y2; y2 = m;
  208.         m = x1; x1 = x2; x2 = m;
  209.         m = c1; c1 = c2; c2 = m;
  210.         m = z1; z1 = z2; z2 = m; };
  211.     x12 = x1 << 16;
  212.     x13 = x1 << 16;
  213.     x23 = x2 << 16;
  214.     z12 = z1;
  215.     z13 = z1;
  216.     z23 = z2;
  217.     c12 = c1 << 16;
  218.     c13 = c1 << 16;
  219.     c23 = c2 << 16;
  220.     if ( y2 != y1 ) { m12  = ( ( x2 - x1 ) << 16 ) / ( y2 - y1 );
  221.                       mc12 = ( ( c2 - c1 ) << 16 )